/**
 * Created by Francis.LW on 2017/10/20.
 *
 * 操作服务接口
 */
import {postRequest, getRequest} from '@/common/request'
import {urls} from './url'

const operationApi = urls.operation

function listAllOperation(mid, success, complete) {
  let param = {}
  if (mid != null) {
    param = {moduleId: mid}
  }
  getRequest(operationApi.listAllOperation, param, success, complete)
}

/**
 * 获取操作列表
 * @param param
 * @param page
 * @param pageSize
 * @param success
 * @param complete
 */
function listOperation(mid, param, page, pageSize, success, complete) {
  postRequest(operationApi.listOperation + mid + '?currentpage=' + page + '&pagesize=' + pageSize, {}, param, success, complete)
}

/**
 * 创建新操作
 * @param param
 * @param success
 * @param complete
 */
function addOperation(param, success, complete) {
  postRequest(operationApi.addOperation, {}, param, success, complete)
}

/**
 * 更新操作信息
 * @param id
 * @param param
 * @param success
 * @param complete
 */
function updateOperation(id, param, success, complete) {
  postRequest(operationApi.updateOperation + id, {}, param, success, complete)
}

/**
 * 获取操作信息
 * @param id
 * @param success
 * @param complete
 */
function getOperationById(id, success, complete) {
  getRequest(operationApi.getOperationById + id, {}, success, complete)
}

/**
 * 删除操作信息
 * @param ids
 * @param success
 * @param complete
 */
function deleteOperation(ids, success, complete) {
  postRequest(operationApi.removeOperation, {}, ids, success, complete)
}

/**
 *
 * @param ids
 * @param success
 * @param complete
 */
function deleteSingleOperation(id, success, complete) {
  let ids = []
  ids.push(id)
  deleteOperation(ids, success, complete)
}

export default {
  listAllOperation,
  listOperation,
  addOperation,
  updateOperation,
  getOperationById,
  deleteOperation,
  deleteSingleOperation
}
